package com.javaoopthree.master;

import com.javaoopthree.Menus;
import com.javaoopthree.User;

import java.util.Scanner;

public class UserMaster {

    //存储用户数组
    User[]  users = new User[10];

    //存储菜单的数组
    Menus[] menus = new Menus[10];

    Scanner scanner = new Scanner(System.in);

    public void UserCrm(){
        System.out.println("-----欢迎进入KH63点餐系统-----");
        LoginMaster();
    }

    public void LoginMaster(){
        boolean isOk=true;
        do {
            System.out.println("请选择您需要的操作：1：登录，2：注册，3：退出");
            int i = scanner.nextInt();
            switch (i){
                case 1:
                    User user = new User();
                    User user1 = user.toLogin(scanner, users);
                    if(user1 !=null){
                        System.out.println("登录成功！");
                        //todo点餐
                        MenusMaster menusMaster = new MenusMaster();
                        menusMaster.toMenuMaster(menus);
                    }else {
                        System.out.println("用户名和密码错误！");
                    }
                    break;
                case 2:
                      registerMaster();
                    break;
                case 3:
                    isOk=false;
                    break;
            }
        }while (isOk);
    }


    //注册循环分支
    public void registerMaster(){
        User user2 = new User();
        boolean isFlag=true;
        do {
            int num = user2.addUser(users, scanner);
            if(num>0){
                isFlag=false;
                System.out.println("注册成功...");
            }
        }while (isFlag);
    }

}
